<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="关联用户id" prop="userId.id"
                :rules="[
                  {required: true, message:'关联用户id不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择关联用户id"
            labelName = 'name'
            labelValue = 'id'
            :value = "inputForm.userId.id"
            :limit="1"
            @getValue='(value) => {inputForm.userId.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="关联企业id" prop="enterpriseId.id"
                :rules="[
                  {required: true, message:'关联企业id不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择关联企业id"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.enterpriseId.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterpriseId.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/list"
            entityBeanName="enterpriseUserInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发布人类型" prop="issuerType"
                :rules="[
                  {required: true, message:'发布人类型不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.issuerType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('issuer_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="佣金" prop="taskMoney"
                :rules="[
                  {required: true, message:'佣金不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskMoney" placeholder="请填写佣金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="佣金类型[暂时不用]" prop="moneyType"
                :rules="[
                  {required: true, message:'佣金类型[暂时不用]不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.moneyType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('money_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务类型(关联任务分类表)" prop="taskType.id"
                :rules="[
                  {required: true, message:'任务类型(关联任务分类表)不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="taskType"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/lhyg/lgy/tasktype/taskType/treeData"
                      :value="inputForm.taskType.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.taskType.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="结算类型" prop="clearingType"
                :rules="[
                  {required: true, message:'结算类型不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.clearingType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('clearing_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="需要人数" prop="needPerson"
                :rules="[
                  {required: true, message:'需要人数不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.needPerson" placeholder="请填写需要人数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="任务图片描述" prop="taskImg"
                :rules="[
                  {required: true, message:'任务图片描述不能为空', trigger:'blur'}
                 ]">
              <el-upload ref="taskImg"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/lhyg/lgy/taskinformation/taskInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {$window.location.href = (file.response && file.response.url) || file.url}"
                    :on-success="(response, file, fileList) => {
                       inputForm.taskImg = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.taskImg = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="taskImgArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务文字描述" prop="taskContent"
                :rules="[
                  {required: true, message:'任务文字描述不能为空', trigger:'blur'}
                 ]">
          <el-input type="textarea" v-model="inputForm.taskContent" placeholder="请填写任务文字描述"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime"
                :rules="[
                  {required: true, message:'开始时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.startTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime"
                :rules="[
                  {required: true, message:'结束时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.endTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务编号" prop="taskNumber"
                :rules="[
                  {required: true, message:'任务编号不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskNumber" placeholder="请填写任务编号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务名称" prop="taskName"
                :rules="[
                  {required: true, message:'任务名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskName" placeholder="请填写任务名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="联系人" prop="linkman"
                :rules="[
                  {required: true, message:'联系人不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.linkman" placeholder="请填写联系人"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="联系电话" prop="linkphone"
                :rules="[
                  {required: true, message:'联系电话不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.linkphone" placeholder="请填写联系电话"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作地址" prop="workAddress"
                :rules="[
                  {required: true, message:'工作地址不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workAddress" placeholder="请填写工作地址"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作地址经度" prop="workAddressLongitude"
                :rules="[
                  {required: true, message:'工作地址经度不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workAddressLongitude" placeholder="请填写工作地址经度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作地址纬度" prop="workAddressLatitude"
                :rules="[
                 ]">
              <el-input v-model="inputForm.workAddressLatitude" placeholder="请填写工作地址纬度"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务特殊需求" prop="workSpecial"
                :rules="[
                  {required: true, message:'任务特殊需求不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workSpecial" placeholder="请填写任务特殊需求"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工作时间" prop="workTime"
                :rules="[
                  {required: true, message:'工作时间不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workTime" placeholder="请填写工作时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="年龄限制" prop="workageLimit"
                :rules="[
                  {required: true, message:'年龄限制不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.workageLimit" placeholder="请填写年龄限制"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="性别限制" prop="worksexLimit"
                :rules="[
                  {required: true, message:'性别限制不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.worksexLimit" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('sex_limit')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="件数" prop="numberUnits"
                :rules="[
                 ]">
              <el-input v-model="inputForm.numberUnits" placeholder="请填写件数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="小时结:工作时长/时，日结:工作天数/天" prop="timeClearing"
                :rules="[
                 ]">
                <el-select v-model="inputForm.timeClearing" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('clearing_type')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务总佣金" prop="totalCommission"
                :rules="[
                 ]">
              <el-input v-model="inputForm.totalCommission" placeholder="请填写任务总佣金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="时间限制" prop="timeLimit"
                :rules="[
                  {required: true, message:'时间限制不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.timeLimit" placeholder="请填写时间限制"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="24">
            <el-form-item label="任务图片单图" prop="taskImgOne"
                :rules="[
                  {required: true, message:'任务图片单图不能为空', trigger:'blur'}
                 ]">
              <el-upload ref="taskImgOne"
                    v-if="visible"
                    :action="`${this.$http.BASE_URL}/sys/file/webupload/upload?uploadPath=/lhyg/lgy/taskinformation/taskInformation`"
                    :headers="{token: $cookie.get('token')}"
                    :on-preview="(file, fileList) => {$window.location.href = (file.response && file.response.url) || file.url}"
                    :on-success="(response, file, fileList) => {
                       inputForm.taskImgOne = fileList.map(item => (item.response && item.response.url) || item.url).join('|')
                    }"
                    :on-remove="(file, fileList) => {
                      $http.post(`/sys/file/webupload/deleteByUrl?url=${(file.response && file.response.url) || file.url}`).then(({data}) => {
                        $message.success(data.msg)
                      })
                      inputForm.taskImgOne = fileList.map(item => item.url).join('|')
                    }"
                    :before-remove="(file, fileList) => {
                      return $confirm(`确定移除 ${file.name}？`)
                    }"
                    multiple
                    :limit="5"
                    :on-exceed="(files, fileList) =>{
                      $message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`)
                    }"
                    :file-list="taskImgOneArra">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">添加相关附件</div>
                  </el-upload>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务审核状态后台审核" prop="auditStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.auditStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('task_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务进行状态" prop="taskRunStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.taskRunStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('task_run_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="任务支付状态" prop="payStatus"
                :rules="[
                 ]">
                <el-select v-model="inputForm.payStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('pay_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余总佣金" prop="surplusMoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.surplusMoney" placeholder="请填写剩余总佣金"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报名人数" prop="applyPeople"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applyPeople" placeholder="请填写报名人数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="报名截止时间" prop="applicationDeadline"
                :rules="[
                 ]">
              <el-input v-model="inputForm.applicationDeadline" placeholder="请填写报名截止时间"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预售服务费" prop="serviceCharge"
                :rules="[
                 ]">
              <el-input v-model="inputForm.serviceCharge" placeholder="请填写预售服务费"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预收税额" prop="taxAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.taxAmount" placeholder="请填写预收税额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="预收总额(包括税额服务费等)" prop="allMoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.allMoney" placeholder="请填写预收总额(包括税额服务费等)"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发票价税合计" prop="billTaxMoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.billTaxMoney" placeholder="请填写发票价税合计"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余服务费" prop="surplusServiceCharge"
                :rules="[
                 ]">
              <el-input v-model="inputForm.surplusServiceCharge" placeholder="请填写剩余服务费"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余税额" prop="surplusTaxAmount"
                :rules="[
                 ]">
              <el-input v-model="inputForm.surplusTaxAmount" placeholder="请填写剩余税额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="剩余总额(包含服务费和税额)" prop="surplusAllMoney"
                :rules="[
                 ]">
              <el-input v-model="inputForm.surplusAllMoney" placeholder="请填写剩余总额(包含服务费和税额)"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="线上订单号" prop="orderNumber"
                :rules="[
                 ]">
              <el-input v-model="inputForm.orderNumber" placeholder="请填写线上订单号"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="支付方式" prop="payment"
                :rules="[
                 ]">
                <el-select v-model="inputForm.payment" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('dealType_E')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        taskImgArra: [],
        taskImgOneArra: [],
        inputForm: {
          id: '',
          userId: {
            id: ''
          },
          enterpriseId: {
            id: ''
          },
          issuerType: '',
          taskMoney: '',
          moneyType: '',
          taskType: {
            id: ''
          },
          clearingType: '',
          needPerson: '',
          taskImg: '',
          taskContent: '',
          startTime: '',
          endTime: '',
          taskNumber: '',
          taskName: '',
          linkman: '',
          linkphone: '',
          workAddress: '',
          workAddressLongitude: '',
          workAddressLatitude: '',
          workSpecial: '',
          workTime: '',
          workageLimit: '',
          worksexLimit: '',
          numberUnits: '',
          timeClearing: '',
          totalCommission: '',
          timeLimit: '',
          taskImgOne: '',
          auditStatus: '',
          taskRunStatus: '',
          payStatus: '',
          surplusMoney: '',
          applyPeople: '',
          applicationDeadline: '',
          serviceCharge: '',
          taxAmount: '',
          allMoney: '',
          billTaxMoney: '',
          surplusServiceCharge: '',
          surplusTaxAmount: '',
          surplusAllMoney: '',
          orderNumber: '',
          payment: ''
        }
      }
    },
    components: {
      GridSelect,
      SelectTree
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建任务信息`
        } else if (method === 'edit') {
          this.title = '修改任务信息'
        } else if (method === 'view') {
          this.title = '查看任务信息'
        }
        this.taskImgArra = []
        this.taskImgOneArra = []
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/taskinformation/taskInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.taskInformation)
              this.inputForm.taskImg.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.taskImgArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.inputForm.taskImgOne.split('|').forEach((item) => {
                if (item.trim().length > 0) {
                  this.taskImgOneArra.push({name: decodeURIComponent(item.substring(item.lastIndexOf('/') + 1)), url: item})
                }
              })
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/taskinformation/taskInformation/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>